package com.funtl.screw.common.security.component;

import com.funtl.screw.common.core.util.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;

/**
 * <p>Title ServiceTokenStoreCleanSchedule</p >
 * <p>Description  </p >
 *
 * @author Lusifer
 * @version 1.0.0
 * @since 2022/4/26 16:22
 */
@Slf4j
@EnableScheduling
@ConditionalOnBean(AuthorizationServerConfigurerAdapter.class)
public class ServiceTokenStoreCleanSchedule {
    @Scheduled(cron = "@hourly")
    public void doMaintenance() {
        ServiceRedisTokenStore tokenStore = SpringContextHolder.getBean(ServiceRedisTokenStore.class);
        long maintenance = tokenStore.doMaintenance();
        log.debug("清理Redis ZADD 过期 token 数量: {}", maintenance);
    }
}
